import 'package:equatable/equatable.dart';
import 'package:mobile_app.core/core/domain/entities/settings/image_settings.dart';
import 'package:mobile_app.core/core/domain/entities/learning_content/lexical_item/lexical_item.dart';
import 'package:mobile_app.core/core/domain/services/image_service/service.dart';
import 'package:mobile_app.home.core/core/domain/helpers/get_lexical_item_effective_image_path/helper.dart';

part 'result.dart';

abstract class HandleImageSettingsOuterUpdate {
  ImageSettingsOuterUpdateHandlingResult call({
    required LexicalItem lexicalItem,
    required ImageSettings imageSettings,
  });
}

class HandleImageSettingsOuterUpdateImpl implements HandleImageSettingsOuterUpdate {
  const HandleImageSettingsOuterUpdateImpl({
    required GetLexicalItemEffectiveImagePath getLexicalItemEffectiveImagePath,
    required ImageService imageService,
  })  : _getLexicalItemEffectiveImagePath = getLexicalItemEffectiveImagePath,
        _imageService = imageService;

  final GetLexicalItemEffectiveImagePath _getLexicalItemEffectiveImagePath;
  final ImageService _imageService;

  @override
  ImageSettingsOuterUpdateHandlingResult call({
    required LexicalItem lexicalItem,
    required ImageSettings imageSettings,
  }) {
    final imagePath = _getLexicalItemEffectiveImagePath(
      lexicalItem: lexicalItem,
      cachedImagePathMap: _imageService.cachedImagePathMap,
      imageEnablementEffective: imageSettings.imageEnablementEffective,
    );

    final result = ImageSettingsOuterUpdateHandlingResult(
      imagePath: imagePath,
    );

    return result;
  }
}
